<?php
/**
 * CRMLite Default Controller
 *
 * @final
 * @package Crmlite_App
 * @version $Id:$
 * @copyright 2006-2007 ETE.CN
 * @author Yi BO  <etng2004@gmail.com>
 * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
 */
require_once dirname(__FILE__) . '/BaseController.php';
final class IndexController extends BaseController
{
	/**
	 * 首页，暂时转向到系统公告页面
	 *
	 */
    public function indexAction()
    {
    	$this->view->show_path = false;
    }
	public function messageAction()
	{
		$message = $this->_getParam('message', 'Unknown notice accrued.');
		$url = $this->_getParam('url', '/');
		$title = $this->_getParam('title', 'Notice');
		$icon = $this->_getParam('icon', 'note');
		$this->view->message = $message;
		$this->view->url = $url;
		$this->view->title = $title;
		$this->view->icon = $icon;
		$this->setTitle("系统提示");
	}
    public function mailAction()
    {
        if($this->isPost())
        {
            $mail_conf = $this->config->mail->toArray();
            $Mailer = new Crmlite_Mail($mail_conf['config']['charset']);
            $Mailer->setTransport($mail_conf['mailer'], $mail_conf['config']);
            $Mailer->setFrom($mail_conf['from'], $this->config->site->title);
            $record = $_POST['fields'];
            $Mailer->addTo($record['receiver']['email'], $record['receiver']['name']);
            $Mailer->setSubject($record['subject']);
            $Mailer->setBodyText($record['content']);
            $Mailer->send();
            if($Mailer->error_count)
            {
                $this->log("Mail Failed:" . $Mailer->ErrorInfo );
                $this->log("Mail Content:" . var_export($record));
               $this->feedback("邮件发送失败,请稍后再试！", "邮件发送失败", $this->module_url, 'error');
            }
            else
            {
                 $this->feedback("邮件发送成功！", "邮件发送成功", $this->module_url, 'note');
            }
        }
        $this->setTitle("邮件助手");
    }
}
